<%@ Page Language="C#" AutoEventWireup="true" CodeFile="OrderView.aspx.cs" Inherits="OrderView" %>

<%@ Register Assembly="DevExpress.Web.ASPxEditors.v9.2, Version=9.2.6.0, Culture=neutral, PublicKeyToken=b88d1754d700e49a"
    Namespace="DevExpress.Web.ASPxEditors" TagPrefix="dxe" %>
<%@ Register Assembly="DevExpress.Web.ASPxGridView.v9.2, Version=9.2.6.0, Culture=neutral, PublicKeyToken=b88d1754d700e49a"
    Namespace="DevExpress.Web.ASPxGridView" TagPrefix="dxwgv" %>
<%@ Register Assembly="DevExpress.Web.v9.2" Namespace="DevExpress.Web.ASPxPager"
    TagPrefix="dxwp" %>
<%@ Register Assembly="DevExpress.Web.v9.2" Namespace="DevExpress.Web.ASPxTabControl"
    TagPrefix="dxtc" %>
<%@ Register Assembly="DevExpress.Web.v9.2" Namespace="DevExpress.Web.ASPxClasses"
    TagPrefix="dxw" %>
<%@ Register Assembly="DevExpress.Web.v9.2" Namespace="DevExpress.Web.ASPxPopupControl"
    TagPrefix="dxpc" %>
<%@ Register Assembly="DevExpress.Web.v9.2" Namespace="DevExpress.Web.ASPxRoundPanel"
    TagPrefix="dxrp" %>
<%@ Register Assembly="DevExpress.Web.v9.2" Namespace="DevExpress.Web.ASPxPanel"
    TagPrefix="dxp" %>
<%@ Register Assembly="DevExpress.Web.v9.2" Namespace="DevExpress.Web.ASPxHiddenField" TagPrefix="dxhf" %>
<%@ Register TagPrefix="wilson" Namespace="Wilson.ORMapper.Web" Assembly="WilsonORMDataSource" %>
<%@ Register Assembly="DevExpress.Web.v9.2" Namespace="DevExpress.Web.ASPxHiddenField"
    TagPrefix="dxhf" %>
<%@ Register Assembly="DevExpress.Web.ASPxGridView.v9.2.Export, Version=9.2.6.0, Culture=neutral, PublicKeyToken=b88d1754d700e49a"
    Namespace="DevExpress.Web.ASPxGridView.Export" TagPrefix="dxwgv" %>
<%@ Register Assembly="DevExpress.Web.v9.2, Version=9.2.6.0, Culture=neutral, PublicKeyToken=b88d1754d700e49a"
    Namespace="DevExpress.Web.ASPxDataView" TagPrefix="dxdv" %>
<%@ Register Assembly="DevExpress.Web.v9.2, Version=9.2.6.0, Culture=neutral, PublicKeyToken=b88d1754d700e49a"
    Namespace="DevExpress.Web.ASPxCallbackPanel" TagPrefix="dxcp" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
    <title>Job Order</title>
    <link href="/Style/StyleSheet.css" rel="stylesheet" type="text/css" />
    <style>
.dxbButton {   	font-size: 11px; }
.txtLabel {font-weight:bold;font-size:11px;}
.txtValue {font-size:11px;}
hr {margin:8px;}
</style>
</head>
<body onload="javascript:LoadMap();">
    <form id="form1" runat="server">

    <script type="text/javascript">
        function ShowEdit() {
            window.open("../Edit/Job.aspx?OrderNo=" + txt_Sn.GetText(), "name1", "width=1020,height=600,toolbar=no,scrollbars=no,menubar=no");
        }
        var clientId = null;
        var clientName = null;
        var clientAdr = null;
        var clientContact = null;
        function PutValue(s, name) {
            if (clientId != null) {
                clientId.SetText(s);
                if (clientName != null) {
                    clientName.SetText(name);
                }
                popubCtr.Hide();
                popubCtr.SetContentUrl('about:blank');
            }
        }
        function PutValue(s, name,address,contact, lat, lon) {
            if (clientId != null) {
                clientId.SetText(s);
                if (clientName != null) {
                    clientName.SetText(name);
                }
                if (clientAdr != null)
                    clientAdr.SetText(address);
                if (clientContact != null)
                    clientContact.SetText(contact);
                popubCtr.Hide();
                popubCtr.SetContentUrl('about:blank');
		document.getElementById("mapframe").contentWindow.SetMap(lat,lon,14);

            }
}

function LoadMap() {
    var la = document.getElementById("lati").innerHTML;
    var lo = document.getElementById("longi").innerHTML;
    if(la != "")
        document.getElementById("mapframe").contentWindow.SetMap(la,lo, 14);
}

        function PopupCust(txtId, txtName,txtAdr,txtContact) {
            clientId = txtId;
            clientName = txtName;
            clientAdr = txtAdr;
            clientContact = txtContact;
            popubCtr.SetContentUrl('/Modules/SelectPage/CustomerPick.aspx');
            popubCtr.SetHeaderText('Customer');
            popubCtr.Show();
        }

        function PopupVehicle(N) {
            parent.parent.PopupItem('/Pages/Sales/EditPage/VehicleEdit.aspx?no=' + N+'&sn=' + txt_OrderNo.GetText(), 'Service Order / Vehicle', 880, 480);
            //popubCtr.SetHeaderText('Service Order / Vehicle');
             //popubCtr.SetContentUrl('/Pages/Sales/EditPage/VehicleEdit.aspx?no=' + N+'&sn=' + txt_OrderNo.GetText());
             //popubCtr.Show();
        }

             var grid = null;
        function AddBill(gridId) {
            grid = gridId;
            popubCtr1.SetHeaderText('Invoice');
            popubCtr1.SetContentUrl('/Modules/Account/EditPage/InvoiceEdit.aspx?InvN=0&sn=' + txt_OrderNo.GetText());
            popubCtr1.Show();
        }
        function ShowBill(gridId, no) {
            grid = gridId;
            popubCtr1.SetHeaderText('Invoice');
            popubCtr1.SetContentUrl('/Modules/Account/EditPage/InvoiceEdit.aspx?InvN=' + no + '&sn=' + txt_OrderNo.GetText());
            popubCtr1.Show();
        }
        function PrintEstimate() {
            window.open("/Reports/printview.aspx?doc=51&no=" + txt_OrderNo.GetText());
        }

        function OnCallback(v) {
            alert(v);
        }
        ////////////////for dropdown list
        function RowClickHandler(s, e) {
            SetLookupKeyValue(e.visibleIndex);
            de_Cust.HideDropDown();
        }
        function SetLookupKeyValue(rowIndex) {
            de_Cust.SetText(gridPopCont.cpKeyValues[rowIndex]);
            txt_CustName.SetText(gridPopCont.cpName[rowIndex]);
            txtAddress.SetText(gridPopCont.cpAddress[rowIndex]);
            txt_CustContact.SetText(gridPopCont.cpContact[rowIndex]);
        }

        /////////////////////////////////////////////////////////////////////////////////////////////////
  </script>

    <div>
         <asp:SqlDataSource ID="dsPickSource" runat="server" ConnectionString="Server=.\Sqlexpress;DataBase=colorworksDB;UID=sa;PWD=1234;"
         SelectCommand="select ddItemCode as Code, ddItemId as Id from ddItems where ddItemStatus='Active' and ddGroupId=1003 order by ddItemSort"  />
         <asp:SqlDataSource ID="dsPickServiceType" runat="server" ConnectionString="Server=.\Sqlexpress;DataBase=colorworksDB;UID=sa;PWD=1234;"
         SelectCommand="select ddItemCode as Code, ddItemId as Id from ddItems where ddItemStatus='Active' and ddGroupId=1009 order by ddItemSort"  />
         <asp:SqlDataSource ID="dsPickOrderStatus" runat="server" ConnectionString="Server=.\Sqlexpress;DataBase=colorworksDB;UID=sa;PWD=1234;"
         SelectCommand="select ddItemCode as Code, ddItemId as Id from ddItems where ddItemStatus='Active' and ddGroupId=1010 order by ddItemSort"  />
         <asp:SqlDataSource ID="dsPickTech" runat="server" ConnectionString="Server=.\Sqlexpress;DataBase=colorworksDB;UID=sa;PWD=1234;"
         SelectCommand="select displayname as Code from [user] where role='Technician' order by name"  />
         <asp:SqlDataSource ID="SqlDataSource4" runat="server" ConnectionString="Server=.\Sqlexpress;DataBase=colorworksDB;UID=sa;PWD=1234;"
         SelectCommand="select ddItemCode as Code, ddItemId as Id from ddItems where ddItemStatus='Active' and ddGroupId=1003 order by ddItemSort"  />


         <wilson:DataSource ID="dsCust" runat="server" ObjectSpace="Touchmax.Manager.ORManager"
                TypeName="Touchmax.BoClient" KeyMember="CustId" FilterExpression="1=1" />
        <wilson:DataSource ID="dsJobOrder" runat="server" ObjectSpace="Touchmax.Manager.ORManager"
            TypeName="Touchmax.OpOrder" KeyMember="Oid" FilterExpression="1=0" />
        <wilson:DataSource ID="dsVehicle" runat="server" ObjectSpace="Touchmax.Manager.ORManager"
            TypeName="Touchmax.OpVehicle" KeyMember="SequenceId" FilterExpression="1=0" />
        <wilson:DataSource ID="dsInvoice" runat="server" ObjectSpace="Touchmax.Manager.ORManager"
            TypeName="Touchmax.OpInvoice" KeyMember="SequenceId" FilterExpression="1=0" />

             <wilson:DataSource ID="dsInvoiceDet" runat="server" ObjectSpace="Touchmax.Manager.ORManager"
                TypeName="Touchmax.OpInvoiceDet" KeyMember="SequenceId" FilterExpression="1=0" />
        <dxwgv:ASPxGridView ID="grid_Order" ClientInstanceName="grid_Order" runat="server"
            DataSourceID="dsJobOrder" Width="440" KeyFieldName="Oid" AutoGenerateColumns="False"
            OnInit="grid_Order_Init" OnInitNewRow="grid_Order_InitNewRow" OnCustomCallback="grid_Order_CustomCallback"
            OnCustomDataCallback="grid_Order_CustomDataCallback" OnHtmlEditFormCreated="grid_Order_HtmlEditFormCreated">
            <SettingsPager Mode="ShowAllRecords">
            </SettingsPager>
            <SettingsEditing Mode="EditForm" />
            <SettingsCustomizationWindow Enabled="True" />
            <Settings ShowColumnHeaders="false" />
            <Templates>
                <EditForm>
                    <table border="0" width="440">
                        <tr>
                            <td Width="90" class="txtLabel">Customer</td>
                            <td width="160" class="txtValue">
                                <%# Eval("CustName") %>
                                
                                        <div style="display:none">
                                        <div id="lati"><%# Eval("Latitude") %></div>
                                        <div id="longi"><%# Eval("Longitude") %></div>
                                        </div>
                            </td>
                            <td rowspan="7">
                            <div style="padding-left:0px;border:solid 2px gray;width:180px;height:180px;">
                            <iframe id="mapframe" frameborder=0 border=0 width=180 height=180 src="/framework/mapsmall.html"></iframe>
                            </div>
                            </td>
                        </tr>
                            <tr>
                            <td>Job Contact
                            </td>
                            <td>
                                <%# Eval("CustContact") %>
                            </td>
                        </tr>
                        <tr>
                            <td  class="txtLabel">
                                Order No
                            </td>
                            <td  class="txtValue">
                                <%# Eval("JobNo") %>
                           
                            </td>

                        </tr>
                        <tr>
                            <td>
                                Service Date
                            </td>
                            <td>
                               <%# Eval("JobDate", "{0:MMM dd, yyyy}") %>
                            </td>
                            </tr>
                            <tr>
                            <td>
                                Marketing Source
                            </td>
                            <td>
                                <%# Eval("JobSource") %>
                            </td>
                            </tr>
                            <tr>
                         <td>
                                Service / Status
                            </td>
                            <td>
                                <%# Eval("JobType") %> /  <%# Eval("JobStatus") %>
                            </td>
                            
                            </tr>
                            <tr>
                            <td>
                                Technician 
                            </td>
                            <td>
                                <%# Eval("Tehnician") %>
                            </td>
                            
                            </tr>
                            <tr>
                            <td valign="top">
                                Remark
                            </td>
                            <td colspan="2">
                                <%# Eval("Remark") %>
                            </td>
                            
                        </tr>
                        
                             </table>
                    
                   </EditForm>
             
            </Templates>
        </dxwgv:ASPxGridView>

        <br />
        
 
                        
                                            <dxwgv:ASPxGridView ID="grd_Cont" ClientInstanceName="grd_Cont" runat="server"
                                                DataSourceID="dsVehicle" KeyFieldName="SequenceId" Width="460"
                                                            OnBeforePerformDataSelect="grd_Cont_BeforePerformDataSelect" OnHtmlRowPrepared="grd_Cont_HtmlRowPrepared">
                                                            <Settings GridLines="Horizontal" />
                                                            <SettingsBehavior ConfirmDelete="True" />
                                                            <SettingsPager Mode="ShowAllRecords">
                                                            </SettingsPager>
                                                <Columns>
                                        
                                                                
                                                                <dxwgv:GridViewDataColumn FieldName="VehicleType" Caption="Vehicle" VisibleIndex="1" Width="150">
                                                                <DataItemTemplate>
                                                                <a onclick='PopupVehicle(<%# Eval("SequenceId") %>);'><%# Eval("Year") %> <%# Eval("VehicleType") %> <%# Eval("VehicleModel") %></a>
                                                                </DataItemTemplate>
                                                                </dxwgv:GridViewDataColumn>
                                                                <dxwgv:GridViewDataColumn FieldName="Color1" Caption="Color" VisibleIndex="1" Width="70">
                                                                </dxwgv:GridViewDataColumn>
                                                                <dxwgv:GridViewDataSpinEditColumn FieldName="Amount" Caption="Amount" VisibleIndex="1" width="60">
                                                                    <propertiesspinedit Increment="0">
                                                                    <spinbuttons showincrementbuttons="False"></spinbuttons>
                                                                    </propertiesspinedit>
                                                                </dxwgv:GridViewDataSpinEditColumn>

                                                                <dxwgv:GridViewDataColumn FieldName="Status" Caption="Status" VisibleIndex="1" Width="70">
                                                                <DataItemTemplate>
                                                                <dxe:ASPxLabel ID="lab_Status" runat="server" Text='<%# Eval("Status") %>'></dxe:ASPxLabel>
                                                                </DataItemTemplate>
                                                                </dxwgv:GridViewDataColumn>
                                              
                                                </Columns>
                                            </dxwgv:ASPxGridView> 
                                            <br />
                                                        <dxwgv:ASPxGridView ID="ASPxGridView2" ClientInstanceName="Grid_Invoice_Import"
                                                            runat="server" KeyFieldName="SequenceId" DataSourceID="dsInvoice" Width="460"
                                                            OnBeforePerformDataSelect="Grid_Invoice_Import_DataSelect">
                                                            <Settings GridLines="Horizontal" /> 

                                                            <Columns>
                                                                <dxwgv:GridViewDataTextColumn Caption="Invoice No" VisibleIndex="0" Width="150">
                                                                    <DataItemTemplate>
                                                                        <a onclick='ShowBill(Grid_Invoice_Import,<%# Eval("DocNo") %>);'><%# Eval("DocNo") %></a>&nbsp;
                                                                    </DataItemTemplate>
                                                                </dxwgv:GridViewDataTextColumn>
                                                                <dxwgv:GridViewDataTextColumn Caption="Date" Width="120" FieldName="DocDate" VisibleIndex="2">
                                <PropertiesTextEdit DisplayFormatString="dd/MM/yyyy">
                                </PropertiesTextEdit>
                                                                </dxwgv:GridViewDataTextColumn>
                                                     
                                                                <dxwgv:GridViewDataTextColumn Caption="Amount" FieldName="TotAmt" VisibleIndex="4">
                                                                </dxwgv:GridViewDataTextColumn>
                                                            </Columns>
                                                        </dxwgv:ASPxGridView>
         
    </div>
    </form>
</body>
</html>
